<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>产品列表页</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>


</head>
<body>
	<table id="homework_dg" title="请假信息" class="easyui-datagrid"
		style="width: 1150px; height: 480px"
		url="${param.request.contextPath}/homework/homeworklist"
		toolbar="homework_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">

		<div id="homework_toolbar">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="newhomework()">新增</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="edithomework()">修改</a> <a
				href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" onclick="destroyhomework()">删除</a>
		</div>

		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<th field="taskId" align="center" align="center">编号</th>
				<th field="startTime" width="50" align="center">作业发布时间</th>
				<th field="endTime" width="50" align="center">作业提交时间</th>
				<th field="type" formatter="typeFormatter" width="30" align="center">作业类型</th>
				<th field="tehId" width="30" align="center" formatter="tehFormatter">发布教师</th>
			</tr>
		</thead>
	</table>

	<div id="homework_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#homework_dlg-buttons">
		<div class="ftitle">作业信息管理</div>
		<form id="homework_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>发布时间:</label> <input name="startTime"
					class="easyui-datetimebox">
			</div>
			<div class="fitem">
				<label>提交时间:</label> <input name="endTime"
					class="easyui-datetimebox">
			</div>
			<div class="fitem">
				<label>作业类型:</label> <input id="type" name="type"
					title="作业类型：0-课堂，1-课后">
			</div>
			<div class="fitem">
				<label>教师编号:</label> <input id="tehId"
					name="teacher.tehId">
			</div>
		</form>
	</div>
	<div id="homework_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="savehomework()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#homework_dlg').dialog('close')">取消</a>
	</div>


	<script type="text/javascript">
		function tehFormatter(value, row, index) {
			return row.teacher.name;
		}
		function typeFormatter(value, row, index) {
			if (value == "0") {
				return "课堂作业";
			}
			if (value == "1") {
				return "课后作业";
			}

		}

		function newhomework() {
			$('#homework_dlg').dialog('open').dialog('setTitle', '新增作业');
			$('#homework_fm').form('clear');
			url = '${pageContext.request.contextPath}/homework/homeworkadd';
		}

		function edithomework() {
			$('#homework_fm').form('clear');
			var row = $('#homework_dg').datagrid('getSelected');
			$('#tehId').val(row.teacher.tehId);
			if (row) {
				$('#homework_dlg').dialog('open').dialog('setTitle', '修改作业布置情况');
				$('#homework_fm').form('load', row);
				url = '${pageContext.request.contextPath}/homework/homeworkedit?taskId='
						+ row.taskId;
			}
		}

		function savehomework() {
			$('#homework_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : '错误信息提示',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : '成功信息提示',
							msg : result.errorMsg
						});
					}

					$('#homework_dlg').dialog('close');
					$('#homework_dg').datagrid('reload');
				}
			});
		}

		function destroyhomework() {
			var row = $('#homework_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除商品?',
								function(r) {
									if (r) {
										$
												.post(
														'${pageContext.request.contextPath}/homework/homeworkdelete',
														{
															taskId : row.taskId
														},
														function(result) {
															if (result.success) {
																$(
																		'#homework_dg')
																		.datagrid(
																				'reload');
															} else {
																$.messager
																		.show({
																			title : 'Error',
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			}
		}
	</script>

</body>
</html>